package com.kaishengit.pojo;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="t_group")
public class Group {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	private String name;
	
	@OneToMany(mappedBy="group",fetch=FetchType.LAZY)
	private List<Permission> permissionList;
	@ManyToMany
	@JoinTable(name="t_user_group",joinColumns=@JoinColumn(name="userid"),inverseJoinColumns=@JoinColumn(name="groupid"))
	private List<User> userList;
	
	@Transient
	public List<String> getPermissionNameSet(){
		List<String> list = new ArrayList<String>();
		for(Permission p : permissionList){
			list.add(p.getPermission());
		}
		return list;
	}
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setPermissionList(List<Permission> permissionList) {
		this.permissionList = permissionList;
	}
	public List<Permission> getPermissionList() {
		return permissionList;
	}
	public void setUserList(List<User> userList) {
		this.userList = userList;
	}
	public List<User> getUserList() {
		return userList;
	}
	
	
}
